<?php

declare (strict_types=1);


namespace App\Models\GameDB\Fantasy;

use App\Models\MainDB\Gift;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class CriticalGift extends Model
{
    protected $connection = 'mysql_game';
    protected $table = 'lottery_fantasy_critical_gift';
    //protected $fillable = [];
    protected $guarded = [];

    //protected $casts = ['id' => 'int', 'user_id' => 'integer', 'amount' => 'integer', 'balance' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function one(array $filters)
    {
        return self::query()->where($filters)->first();
    }

    public function listAll(array $filters, array $fields)
    {
        return self::query()->where($filters)->select($fields)->get();
    }

    public function getListWithLevel(array $filters, array $fields)
    {
        $query = self::query()->select($fields)->join(app('model_fantasy_level')->getTable(),
            $this->getTable() . '.level', '=', app('model_fantasy_level')->getTable() . ".level");
        return $query->where($filters)->get();
    }

    public function getLevelGift($level, $fields)
    {
        return self::query()->select($fields)->join(app('model_fantasy_level')->getTable(),
            $this->getTable() . '.level', '=', app('model_fantasy_level')->getTable() . ".level")
            ->where([$this->getTable() .'.level' => $level, $this->getTable() . '.status' => 1])
            ->where('count', '>', 0)->first();
    }

    public function updateData(array $filters, $data)
    {
        return self::query()->where($filters)->update($data);
    }

}